# $Id: Makefile.in,v 1.7 1995/05/25 08:25:38 deans Exp $

#------------------------------------------------------------------------------
# Configuration options.
#------------------------------------------------------------------------------

# Built Source directory for Tcl relative to this directory or root.  Otcl
# currently works with either Tcl 7.3 or Tcl 7.4b3.  This define maybe omitted
# if the other TCL_* defines below are explictly set to the installed
# locations.
TCL_DIR         =       ../tcl-7.3

# The location of the Tcl public includes files (tcl.h)
TCL_INCLDIR	= 	${TCL_DIR}

# The location of the Tcl private includes file (tclInt.h)
TCL_SRCDIR	= 	${TCL_DIR}

# The location of the Tcl library (libtcl.a)
TCL_LIBDIR	= 	${TCL_DIR}

# Built Source directory for Tk relative to this directory or root.  Otcl
# currently works with either Tk 3.6 or Tk 4.0b3.  This define maybe omitted
# if the other TK_* defines below are explictly set to the installed
# locations.
TK_DIR          =       ../tk3.6


# The location of the Tk public includes files (tk.h)
TK_INCLDIR	= 	${TK_DIR}

# The location of the Tk library (libtk.a)
TK_LIBDIR	= 	${TK_DIR}

# Installation directories
prefix          =       @prefix@
exec_prefix     =       @exec_prefix@

BIN_DIR         =       ${exec_prefix}/bin
LIB_DIR         =       ${exec_prefix}/lib
INCL_DIR        =       ${prefix}/include
HTML_DIR        =       ${prefix}/html/otcl

CXX		= 	@CXX@
CXXFLAGS	=	@CXXFLAGS@ -DOTCL_DP
AR		= 	ar
RANLIB		= 	@RANLIB@
INSTALL =		@INSTALL@
INSTALL_PROGRAM =	@INSTALL_PROGRAM@
INSTALL_DATA    =	@INSTALL_DATA@
MKDIRS          =	./mkdirs

#------------------------------------------------------------------------------
# Other definitions.
#------------------------------------------------------------------------------

CXXINCLUDES	= 	-I. \
		  	-I$(TCL_INCLDIR) \
		  	-I$(TCL_SRCDIR) \
			-I$(TK_INCLDIR)

CDL		= 	cdl

INSTINCL	=	Otcl.H OtclClass.H OtclError.H OtclObjMgr.H \
                        OtclObject.H OtclPart.H

INSTHTML	=       BindingRef.html LangRef.html Overview.html

LIB_OBJECTS	=	Otcl.o \
			OtclVarArgs.o \
			OtclClass.o \
			OtclMethod.o \
			OtclAttribute.o \
			OtclObjMgr.o \
			OtclObject.o \
			OtclPart.o \
			OtclFormalArg.o \
			OtclOserver.o

OTCLSH_OBJECTS	=	tclAppInit.o

TKLIB_OBJECTS	=	tkMain.o

TCLLIB_OBJECTS	=	tclMain.o

OWISH_OBJECTS	=	tkAppInit.o

TEST_OBJECTS	=	Test.o \
			Test_cdl.o \
			TestAppInit.o

TEST_HEADERS	=	Test_cdl.H

CDL_OBJECTS	=	CdlFile.o \
			CdlItem.o \
			CdlArg.o \
			CdlRtn.o \
			CdlMethod.o \
			cdlMain.o

TCL_LIBS	=	-L$(TCL_LIBDIR) -ltcl

TK_LIBS		=	-L$(TK_LIBDIR) -ltk

X11LIBS		=	@XLIBSW@

SYSLIBS		=	@LIBS@ @MATH_LIBS@

.SUFFIXES: .cdl .H .C

.C.o:
			$(CXX) $(CXXFLAGS) $(CXXINCLUDES) -c $<
.cdl.o:
			$(CDL) -s $< $*.C
			$(CXX) $(CXXFLAGS) $(CXXINCLUDES) -c $*.C
			rm $*.C

.cdl.H:
			$(CDL) -h $< $*.H

#------------------------------------------------------------------------------
# Rules.
#------------------------------------------------------------------------------

all:		libotcl.a cdl otclsh otcltest owish

libotcl.a:	$(LIB_OBJECTS) $(TCLLIB_OBJECTS) $(TKLIB_OBJECTS)
		rm -f libotcl.a
		$(AR) cr libotcl.a $(LIB_OBJECTS) $(TCLLIB_OBJECTS) \
			$(TKLIB_OBJECTS)
		$(RANLIB) libotcl.a

otclsh:		libotcl.a $(OTCLSH_OBJECTS)
		$(CXX) $(CXXFLAGS) $(CXXINCLUDES) $(LDFLAGS) -o otclsh \
			$(OTCLSH_OBJECTS) libotcl.a $(TCL_LIBS) $(SYSLIBS)

owish:		libotcl.a $(OWISH_OBJECTS)
		$(CXX) $(CXXFLAGS) $(CXXINCLUDES) $(LDFLAGS) -o owish \
			$(OWISH_OBJECTS) libotcl.a $(TK_LIBS) \
			$(TCL_LIBS) $(X11LIBS) $(SYSLIBS)

otcltest:	libotcl.a $(CDL) $(TEST_HEADERS) $(TEST_OBJECTS)
		$(CXX) $(CXXFLAGS) $(CXXINCLUDES) $(LDFLAGS) -o otcltest \
			$(TEST_OBJECTS) libotcl.a $(TCL_LIBS) $(SYSLIBS)

cdl:		$(CDL_OBJECTS)
		$(CXX) $(CXXFLAGS) $(CXXINCLUDES) -o cdl $(CDL_OBJECTS) \
			$(TCL_LIBS) $(SYSLIBS)

test: otcltest
		(cd tests; ../otcltest tscript)

install:	install-binaries install-html

install-binaries: libotcl.a otclsh $(BIN_DIR) $(LIB_DIR) $(INCL_DIR)
	@echo "Installing otclsh"
	@$(INSTALL_PROGRAM) otclsh $(BIN_DIR)/otclsh
	@echo "Installing owish"
	@$(INSTALL_PROGRAM) owish $(BIN_DIR)/owish
	@echo "Installing libotcl.a"
	@$(INSTALL_DATA) libotcl.a $(LIB_DIR)/libotcl.a
	@for i in $(INSTINCL) ; do \
	    echo "Installing $$i";\
	    $(INSTALL_DATA) $$i $(INCL_DIR)/$$i; \
	done

install-html: $(HTML_DIR)
	@for i in $(INSTHTML) ; do \
	    echo "Installing $$i"; \
	    $(INSTALL_DATA) docs/$$i $(HTML_DIR)/$$i; \
	done

$(BIN_DIR):
	${MKDIRS} $(BIN_DIR)

$(LIB_DIR):
	${MKDIRS} $(LIB_DIR)

$(INCL_DIR):
	${MKDIRS} $(INCL_DIR)

$(HTML_DIR):
	${MKDIRS} $(HTML_DIR)
		
clean:
		rm -f *.o libotcl.a otclsh otcltest cdl core *..dbx *_cdl.C \
		*_cdl.H owish

distclean:	clean
		rm -f Makefile config.status config.cache config.log 
